<?php
require_once BaseUtil::getModulePath("base") . '/models/BaseDao.php';
class AdminDao extends BaseDao
{
    protected $_name;

    public function  _setup() {
        $this->_name = $this->prefix() . "admins";
        parent::_setup();
    }

    public function updateAdmin($admin,$id){
         $where = $this->db_w->quoteInto('id = ?', $id);
         $this->updateData($admin,$where);
    }

    public function getAdminById($id){
        $select = $this->db_r->select();
        $select->from($this->_name,"*");
        $select->where('id = ?', $id);
        $sql = $select->__toString();
        $result = $this->db_r->fetchRow($sql);
        return $result;
    }

    public function getAdmin($email,$password){
        $select = $this->db_r->select();
        $select->from($this->_name,"*");
        $select->where('email = ?', $email);
        $select->where('password = ?', md5($password));
        $select->where('is_delete = 0');
        $sql = $select->__toString();
        $result = $this->db_r->fetchRow($sql);
        return $result;
    }
    
    public function getAllAdmins(){
    	$select = $this->db_r->select();
        $select->from($this->_name,"*");
        $select->where('is_delete = 0');
        $sql = $select->__toString();
        $result = $this->db_r->fetchAll($sql);
        return $result;
    }
}